<template>
  <form>
    <div class="form-group">
      <label class="col-sm-12 control-label">
        <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
        到达时间</label>
      <div class="col-sm-12">
        <input readonly="readonly" type="text" v-model="f_onsite_time" class="form-control"/>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-12 control-label">
        <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
        离开时间</label>
      <div class="col-sm-12">
        <input readonly="readonly" type="text" v-model="f_offsite_time" class="form-control"/>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-12 control-label">
        <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
        入户状态</label>
      <div :class="style__" class="col-sm-12">
        <radio-group :value.sync="f_entry_status" :type="f_entry_class" buttons="false">
          <radio value="未使用天然气">未使用天然气</radio>
          <radio value="到访不遇">到访不遇</radio>
          <radio value="拒检">拒检</radio>
          <radio value="入户">入户</radio>
        </radio-group>
      </div>
      <div :class="style__" class="form-group" v-show="f_entry_status=='未使用天然气'">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          未使用天然气照片：</label>
        <div class="col-sm-12">
          <img  :class="style__" @click="takePic('f_nongasuser_path', '未使用天然气照片')" :src="f_nongasuser_path" alt="未使用天然气照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span  :class="style__" class="glyphicon glyphicon-trash" @click="delfile('f_nongasuser_path', this.f_nongasuser_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.f_nongasuser_path)"></span>
        </div>
      </div>
      <div class="form-group" v-show="f_entry_status=='到访不遇'">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          到访不遇照片：</label>
        <div class="col-sm-12">
          <img  :class="style__" @click="takePic('f_noanswer_path', '到访不遇照片')" :src="f_noanswer_path" alt="到访不遇照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span  :class="style__" class="glyphicon glyphicon-trash" @click="delfile('f_noanswer_path', this.f_noanswer_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.f_noanswer_path)"></span>
        </div>
      </div>
    </div>
    <div :class="style__" class="form-group">
      <label class="col-sm-12 control-label">
        <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
        处置方式</label>
      <div class="col-sm-12">
          <input type="checkbox" v-model="f_no_gas_device">无燃气具</input>
          <input type="checkbox" v-model="f_close_valve">关闭表前阀</input>
          <input type="checkbox" v-model="f_unload_battery">取下表内电池</input>
      </div>
    </div>
    <div style="height:50px;"></div>
  </form>
</template>

<script>
import RadioGroup from 'vue-strap/src/radioGroup'
import Radio from 'vue-strap/src/radioBtn'
import Vue from 'vue'
import * as Util from '../Util'

export default {
  title: '安检概况',
  data() {
    return {
    }
  },
  methods: {
    cameraCallBack(prop, fileName) {
        HostApp.__this__.$set(prop, fileName + '?' + Math.random())
        console.log('photo file name:' + HostApp.__this__.f_nongasuser_path)
        HostApp.__callback__ = null
        HostApp.__this__ = null
    },
    takePic(prop, title) {
      HostApp.__callback__ = this.cameraCallBack
      HostApp.__this__ = this
      console.log('this[prop]:' + this[prop])
      let fileName
      if(!this[prop] || this[prop].includes("nopic.png")) {
        fileName = Util.guid() +'-' + prop + '.jpg'
      } else {
        fileName = Util.getFileName(this[prop])
      }
      HostApp._open_a_page({type: 'boomerang',
        page: 'com.aofeng.hybrid.android.peripheral.CameraActivity',
        param: {file: fileName, requestCode: 111, callback:'javascript:HostApp.__callback__("' + prop +'", "%s");', watermark: title + '\t时间：'+ Util.toStandardTimeString() + '\t' + Vue.user.name}
      })
    },
    delfile(prop, fileName) {
      if(fileName == Vue.nopic)
        return
      else {
        HostApp.delfile(fileName)
        this[prop] = Vue.nopic
      }
    },
    setEntryClass (val) {
      if(val == '未使用天然气')
        this.$set('f_entry_class', 'default')
      else if (val == '到访不遇')
        this.$set('f_entry_class', 'warning')
      else if (val == '拒检')
        this.$set('f_entry_class', 'danger')
      else if (val == '入户')
        this.$set('f_entry_class', 'success')
    }
  },
  components: {
    RadioGroup,
    Radio
  },
  ready() {
    this.$data = this.$parent.$parent.data
    if (this.$parent.$parent.role == 'repair') {
      this.$set('style__', 'divmask')
      this.$set('style_view_', '')
    }
    else if (this.$parent.$parent.role == 'view'){
      this.$set('style__', 'divmask')
      this.$set('style_view_', 'divmask')
      console.log('set style for ....')
    } else {
      this.$set('style__', '')
      this.$set('style_view_', '')
    }
    if(!this.f_nongasuser_path)
      this.$set('f_nongasuser_path', Vue.nopic)
    if(!this.f_noanswer_path)
      this.$set('f_noanswer_path', Vue.nopic)

    this.setEntryClass(this.f_entry_status)
    this.$watch('f_entry_status', (val) => {
      this.setEntryClass(val)

      if(val != '未使用天然气') {
        this.f_nongasuser_path = Vue.nopic
      }
      if(val != '到访不遇') {
        this.f_noanswer_path = Vue.nopic
      }
      if(val != '入户') {
        //清理安检概括
        this.f_no_gas_device = false
        this.f_unload_battery = false
        this.f_close_valve = false
        //清理全局隐患
        this.f_defect_cramped = false
        this.f_defect_bedroom = false
        this.f_defect_longpipe = false
        this.f_defect_firesource = false
        this.f_defect_explosive = false
        this.f_defect_viacabinet = false
        this.f_defect_intermittent = false
        this.f_defect_nearfire = false
        this.f_defect_openkitchen = false
        this.f_defect_hang = false
        this.f_cramped_path = Vue.nopic
        //用户评价
        this.f_client_evaluation = null
        //清设备
        this.$set('f_meters', [])
        this.$set('f_plumbs', [])
        this.$set('f_valves', [])
        this.$set('f_inner_plumbs', [])
        this.$set('f_alarms', [])
        this.$set('f_cookers', [])
        this.$set('f_heaters', [])
        this.$set('f_furnaces', [])
        //TODO 删除已有的照片
      }
    })
  }
}
</script>
